5-客户端推送 PUSH

接收客户端的PUSH请求,请求处理器走的SPI机制,业务实现由SPI扩展实现;

1
2
//ConnectionServer#init()
messageDispatcher.register(Command.PUSH, PushHandlerFactory::create);

1
2
3
4
5
public interface PushHandlerFactory extends Factory<MessageHandler> {
static MessageHandler create() {
return SpiLoader.load(PushHandlerFactory.class).get();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@Spi(order = 1)
public final class ClientPushHandler extends BaseMessageHandler<PushMessage> implements PushHandlerFactory {
@Override
public PushMessage decode(Packet packet, Connection connection) {
return new PushMessage(packet, connection);
}
@Override
public void handle(PushMessage message) {
Logs.PUSH.info("receive client push message={}", message);

if (message.autoAck()) {
AckMessage.from(message).sendRaw();
Logs.PUSH.info("send ack for push message={}", message);
}
//biz code write here
}
@Override
public MessageHandler get() {
return this;
}
}



接入服务文章目录:

------ 本文结束 感谢您的阅读 ------